import java.util.Arrays;

public class Test {
    //有效三角形的个数
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int end = nums.length - 1;
        int count = 0;
        while(end >= 0){
            int left = 0;
            int right = end - 1;
            while(left <= right){
                if(nums[left] + nums[right] > nums[end]){
                    count = count + right - left;
                    right--;
                }else {
                    left++;
                }
            }
            end--;
        }
        return count;
    }
}
